<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field['options'].displayStyle"
  >
    <div class="scene-window-widget" :style="getStyle('area')">
      <div class="window-area">
        <div class="replenish" v-if="optionsInfo['replenishShown']">
          <ScrollX>{{ optionsInfo.replenishContent }}</ScrollX>
        </div>
        <div class="window-info flex-box">
          <div class="flex-box-left flex-item" :style="getStyle('number')" v-if="optionsInfo['roomNumberShown']">
            {{ optionsInfo['roomNumberAuto'] ? optionsInfo['roomNumber'] : getWindowDeptInfo['roomNo'] }}
          </div>
          <div class="flex-box-right">
            <div class="title" :style="getStyle('title')">
              {{ optionsInfo['patientListTitle'] || '当前待取药的患者'}}
            </div>
            <div class="content">
              <template v-for="(item) in getRoomDoctorInfo">
                <div class="content-item" :class="{'content-item-left':optionsInfo['patientOrderNoShown']}">
                  <p v-for="(itemInfo2,index) in item" :key="index">
                    <template v-if="itemInfo2['number']">
                      <span class="orderNo"
                            v-if="!!(itemInfo2?.number)&&optionsInfo['patientOrderNoShown']"
                            :style="getStyle('patientOrderNo')"
                            :class="{'patient-orderNo':optionsInfo['patientOrderNoShown']}"
                      >
                        {{ itemInfo2?.number || '\u00a0' }}
                      </span>
                    </template>
                    <template v-if="itemInfo2['patientName']">
                      {{ itemInfo2?.patientName || '\u00a0' }}
                    </template>
                  </p>
                </div>
              </template>
            </div>
          </div>
        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import emitter from "@/utils/designer/emitter";
import {pxToVw} from '@/utils/common';
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue';
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";

export default {
  name: "scene-window-patientList-info-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
    //prop传入的表单JSON配置
    parentApi: {
      type: Object,
      default: () => buildParentApi()
    },
  },

  data() {
    return {
      optionsInfo: Object(),
      header: require("@a/images/design/header.jpeg"),
      pause: require("@a/images/design/pause.png"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            return Obj;
          case 'room':
            Reflect.set(Obj, 'fontSize', pxToVw(info.roomNameFontSize));
            return Obj;
          case 'number':
            Reflect.set(Obj, 'fontSize', pxToVw(info.roomNumberFontSize));
            return Obj;
          case 'patientOrderNo':
            Reflect.set(Obj, 'color', (info.patientOrderFontColor));
            Reflect.set(Obj, 'background', (info.patientOrderBackground));
            return Obj;
          case 'title':
            Reflect.set(Obj, 'fontSize', pxToVw(info.patientListTitleFontSize));
            Reflect.set(Obj, 'fontWeight', (info.patientListTitletFontWeight));
            Reflect.set(Obj, 'color', (info.patientListTitleFontColor));
            Reflect.set(Obj, 'background', (info.patientListTitleBackground));
            return Obj;
        }
      }
    },

    // 获取科室信息
    getWindowDeptInfo() {
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getWindowDeptInfoInfo'];
      if (devType) {
        return roomDoctorInfo.apiData;
      } else {
        return roomDoctorInfo.mockData;
      }
    },

    //获取窗口-患者信息
    getRoomDoctorInfo() {
      let devType = (this.devType);
      let {patientListRow, patientListCol} = (this.optionsInfo);
      let totalNumber = (patientListRow * patientListCol);
      let roomDoctorInfo = this.$store.getters['getWindowPatientListInfo'];
      let data = Array();
      if (devType) {
        data = roomDoctorInfo.apiData || Array()
      } else {
        data = roomDoctorInfo.mockData || Array()
      }
      // 不足-补足指定的条数
      if (data.length > totalNumber) {
        let sliceArr = data.slice(0, totalNumber);
        return this.$lodash.chunk(sliceArr, patientListCol)
      } else {
        let arr = (new Array(totalNumber - data.length).fill({}));
        let sliceArr = [...data, ...arr];
        return this.$lodash.chunk(sliceArr, patientListCol)
      }
    },

  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "publishListInfo":
          console.log(`医生-患者-信息-${data}`);
          this.$store.dispatch('setWindowPatientListInfo', this.$lodash.cloneDeep(data))
          break
      }
    },

  },

  watch: {
    field: {
      handler: function (val) {
        let key = (val.options.config)
        this.optionsInfo = (val.options[key]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-window-widget {
  color: #333;
  height: 150px;
  font-size: 40px;
  padding: 28px 30px;
  box-sizing: border-box;
  flex: inherit;
  flex-direction: column;
  justify-content: space-between;
  background: transparent;
  overflow: hidden;

  .window-area {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;

    .replenish {
      width: 100%;
      font-size: 80px;
      color: #0059B3;
      line-height: 112px;
      text-align: center;
      font-style: normal;
      @include fontWeight()
    }

    .window-info {

      .flex-item {
        overflow: hidden;
        color: #FFFFFF;
        display: flex;
        text-align: center;
        align-items: center;
        justify-content: center;
        border: none;
      }

      .flex-box-left {
        flex-basis: calc(30% - 16px);
        font-weight: bolder;
        font-size: 460px;
        background: rgba(0, 80, 161, 1);
        border-radius: 20px;
        overflow: hidden;
        box-sizing: border-box;
        margin-right: 16px;
        box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
        inset -1px -1px 10px rgba(0, 0, 0, 0.2);
      }

      .flex-box-right {
        flex-basis: calc(70%);
        display: flex;
        flex-direction: column;
        border-radius: 20px;
        box-sizing: border-box;
        overflow: hidden;
        box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
        inset 15px 15px 10px rgba(255, 255, 255, 0.75),
        inset -1px -1px 10px rgba(0, 0, 0, 0.2);

        .title {
          font-size: 64px;
          color: white;
          padding: 28px 0;
          text-align: center;
          background: rgba(0, 80, 161, 1);
        }

        .content {
          display: flex;
          flex-direction: column;
          flex-grow: 1;
          height: 100%;
          width: 100%;

          .content-item {
            display: flex;
            flex-direction: row;
            align-items: center;
            align-self: center;
            width: 100%;
            flex-basis: calc(100% / 3);
            border-bottom: 8px #E5EAEF solid;
            flex-grow: 1;
            flex-shrink: 1;

            p {
              @include singleEllipsis(100%);
              display: flex;
              align-items: center;
              align-self: center;
              height: 100%;
              justify-content: center;
              flex: 1;
              font-size: 50px;
              padding: 0 32px 0 32px;
              border-right: 8px #E5EAEF solid;


              &:last-child {
                border-right: none;
              }

              .orderNo {
                font-size: 42px;
                padding-right: 16px;
              }
              .patient-orderNo{
                display: inline-flex;
                min-width: 152px;
                justify-content: center;
                background: #14314B;
                border-radius: 10px;
                overflow: hidden;
                color: #EBEEF5;
                padding: 8px 0;
                margin-right: 16px;
              }
            }

            &:last-child {
              border-bottom: none;
            }
          }
          .content-item-left{
            p {
              justify-content: left;
            }
          }
        }
      }
    }
  }
}
</style>